import 'package:flutter/cupertino.dart';

class AssetsImageWrap extends StatelessWidget {
  final String url;
  final AssetBundle? bundle;
  final String? package;
  final BoxFit? fit;
  final BoxConstraints? constraints;

  /// 圆角  [borderRadius]为[Null]有效
  final double? radius;
  final BorderRadius? borderRadius;
  final double? borderWidth;
  final Color? borderColor;
  final ColorFilter? colorFilter;

  /// 占位图
  final Widget? placeHolder;

  AssetsImageWrap({
    super.key,
    required this.url,
    this.bundle,
    this.package,
    double? width,
    double? height,
    BoxConstraints? constraints,
    this.fit,
    this.radius,
    this.borderWidth,
    this.borderColor,
    this.borderRadius,
    this.placeHolder,
    this.colorFilter,
  }) : constraints = (width != null || height != null)
            ? constraints?.tighten(width: width, height: height) ??
                BoxConstraints.tightFor(width: width, height: height)
            : constraints;

  @override
  Widget build(BuildContext context) {
    Widget result = Container(
      constraints: constraints,
      decoration: BoxDecoration(
        borderRadius: borderRadius ?? BorderRadius.circular(radius ?? 0),
        image: DecorationImage(
            image: AssetImage(url, bundle: bundle, package: package),
            fit: fit ?? BoxFit.cover,
            colorFilter: colorFilter),
        border: borderWidth == null
            ? null
            : Border.all(color: borderColor!, width: borderWidth!),
      ),
    );
    return result;
  }
}
